using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CRMDomain;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model.DataInterfaces.PersonDataInterf;
using ShivamEMR.Model.DataInterfaces.CRMDataInterf;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.CRM.Controllers
{   
    public class AssignementController : Controller
    {
		private readonly IEmployeeRepository employeeRepository;
		private readonly IPersonRepository personRepository;
		private readonly IVenueRepository venueRepository;
		private readonly IAssignmentGroupRepository assignmentgroupRepository;
		private readonly IAssignmentStatusRepository assignmentstatusRepository;
		private readonly IAdmissionRepository admissionRepository;
		private readonly IAssignmentRepository assignmentRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public AssignementController() //: this(new EmployeeRepository(), new PersonRepository(), new VenueRepository(), new AssignmentGroupRepository(), new AssignmentStatusRepository(), new AdmissionRepository(), new AssignmentRepository())
        {
            this.employeeRepository = Registry.RepositoryFactory.GetEmployeeRepository();
            this.personRepository = Registry.RepositoryFactory.GetPersonRepository();
            this.venueRepository = Registry.RepositoryFactory.GetVenueRepository();
            this.assignmentgroupRepository = Registry.RepositoryFactory.GetAssignmentGroupRepository();
            this.assignmentstatusRepository = Registry.RepositoryFactory.GetAssignmentStatusRepository();
            this.admissionRepository = Registry.RepositoryFactory.GetAdmissionRepository();
            this.assignmentRepository = Registry.RepositoryFactory.GetAssignmentRepository();
        }

        public AssignementController(IEmployeeRepository employeeRepository, IPersonRepository personRepository, IVenueRepository venueRepository, IAssignmentGroupRepository assignmentgroupRepository, IAssignmentStatusRepository assignmentstatusRepository, IAdmissionRepository admissionRepository, IAssignmentRepository assignmentRepository)
        {
			this.employeeRepository = employeeRepository;
			this.personRepository = personRepository;
			this.venueRepository = venueRepository;
			this.assignmentgroupRepository = assignmentgroupRepository;
			this.assignmentstatusRepository = assignmentstatusRepository;
			this.admissionRepository = admissionRepository;
			this.assignmentRepository = assignmentRepository;
        }

        //
        // GET: /Assignement/

        public ViewResult Index()
        {
            return View(assignmentRepository.All);//Including(assignment => assignment.Employee, assignment => assignment.Person, assignment => assignment.Venue, assignment => assignment.Admission));
        }

        //
        // GET: /Assignement/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(assignmentRepository.Find(id));
        }

        //
        // GET: /Assignement/Create

        public ActionResult Create()
        {
			ViewBag.PossibleEmployees = employeeRepository.All;
			ViewBag.PossiblePeople = personRepository.All;
			ViewBag.PossibleVenues = venueRepository.All;
			ViewBag.PossibleAssignmentGroups = assignmentgroupRepository.All;
			ViewBag.PossibleAssignmentStatus = assignmentstatusRepository.All;
			ViewBag.PossibleAdmissions = admissionRepository.All;
            var assign = new Assignment() { DateAndTime=DateTime.Now };
            return View(assign);
        } 

        //
        // POST: /Assignement/Create

        [HttpPost]
        public ActionResult Create(Assignment assignment)
        {
            if (ModelState.IsValid) {
                assignmentRepository.Create(assignment);
                assignmentRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleEmployees = employeeRepository.All;
				ViewBag.PossiblePeople = personRepository.All;
				ViewBag.PossibleVenues = venueRepository.All;
				ViewBag.PossibleAssignmentGroups = assignmentgroupRepository.All;
				ViewBag.PossibleAssignmentStatus = assignmentstatusRepository.All;
				ViewBag.PossibleAdmissions = admissionRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Assignement/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleEmployees = employeeRepository.All;
			ViewBag.PossiblePeople = personRepository.All;
			ViewBag.PossibleVenues = venueRepository.All;
			ViewBag.PossibleAssignmentGroups = assignmentgroupRepository.All;
			ViewBag.PossibleAssignmentStatus = assignmentstatusRepository.All;
			ViewBag.PossibleAdmissions = admissionRepository.All;
             return View(assignmentRepository.Find(id));
        }

        //
        // POST: /Assignement/Edit/5

        [HttpPost]
        public ActionResult Edit(Assignment assignment)
        {
            if (ModelState.IsValid) {
                assignmentRepository.Update(assignment);
                assignmentRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleEmployees = employeeRepository.All;
				ViewBag.PossiblePeople = personRepository.All;
				ViewBag.PossibleVenues = venueRepository.All;
				ViewBag.PossibleAssignmentGroups = assignmentgroupRepository.All;
				ViewBag.PossibleAssignmentStatus = assignmentstatusRepository.All;
				ViewBag.PossibleAdmissions = admissionRepository.All;
				return View();
			}
        }

        //
        // GET: /Assignement/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(assignmentRepository.Find(id));
        }

        //
        // POST: /Assignement/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var a = assignmentRepository.Find(id);
            assignmentRepository.Delete(a);
            assignmentRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

